#include <stdio.h>

void byteorder()
{
    // Using predine macro
    if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
    {
    }

    if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
    {
    }

    // or

    union
    {
        short value; // 2byte
        char union_bytes[sizeof(short)];
    } test;
    test.value = 0x0102;
    if (test.union_bytes[0] == 1 && test.union_bytes[1] == 2)
    {
        // big endian
    }
    else if (test.union_bytes[0] == 2 && test.union_bytes[1] == 1)
    {
        // small endian
    }
    else
    {
        printf("unkown..\n");
    }
}